home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 351-375 / 371 / fractals / src / colorwindow.c next >
C/C++ Source or Header  |  1995-03-14  |  10KB  |  400 lines

  1. /* colorwindow.c ranxerox v4.1 890820 891217 */
  2. #include <intuition/intuition.h>
  3. #include <exec/types.h>
  4. #define Rp CW_cwdw->RPort
  5. #define ABS(x) ((x)>0)?(x):-(x)
  6. typedef enum { NOTHING,EXIT,REDUP,GREENUP,BLUEUP,REDDOWN,GREENDOWN,BLUEDOWN
  7.              , RED,GREEN,BLUE,WAVE1,WAVE2,WAVE3,WAVE4,WAVE5,WAVE6,MOVE}
  8.         VALUES;
  9.  
  10. #define MAXWAVES 2
  11. #define REDLEFT 0x000020
  12. #define GRELEFT 0x000040
  13. #define BLULEFT 0x000080
  14. #define COLLEFT REDLEFT|GRELEFT|BLULEFT
  15. #define REDRIGHT 0x000100
  16. #define GRERIGHT 0x000200
  17. #define BLURIGHT 0x000400
  18. #define COLRIGHT REDRIGHT|GRERIGHT|BLURIGHT
  19.  
  20. extern struct IntuitionBase *IntuitionBase;
  21. extern struct GfxBase *GfxBase;
  22.  
  23. void CloseWindow(),RectFill(),SetAPen(),SetDrMd(),ReplyMsg(),Move();
  24. void WritePixel(),_CWDrawWindow(),_CWSetColMap(),_CWRight(),_CWLeft();
  25. void _CWDRGB(),_CWBox(),Delay(),Draw(),_CWWave(),_CWDown(),_CWUp(),SetRGB4();
  26. short GetRGB4();
  27. long Text(),_CWGetChoice(),Wait();
  28. struct View *ViewPortAddress();
  29. struct Message *GetMsg();
  30. struct Window *OpenWindow();
  31.  
  32. static struct Window *CW_cwdw;
  33. static struct ViewPort *CW_WVP;
  34. static char CW_red[32],CW_green[32],CW_blue[32];
  35. static long CW_RGBflag,CW_WaveFlag;
  36.  
  37. static struct NewWindow CW_nwdw={150,50,150,150,0,1,MOUSEBUTTONS,
  38.               ACTIVATE|WINDOWDRAG|WINDOWDEPTH,
  39.               NULL,NULL,(UBYTE *)"COLORWINDOW 4.1",NULL,NULL,0,0,0,0,
  40.               CUSTOMSCREEN
  41.                };
  42. static struct CW_1 { short Xmin,Ymin,Xmax,Ymax; };
  43. static struct CW_1 CW_s1[]={ 10,70,140,120,
  44.               10,134,45,140,15,53,135,60,15,85,45,95,60,85,90,95,
  45.               105,85,135,95,15,105,45,115,60,105,90,115,105,105,135,115
  46.                };
  47. static struct CW_2 { short X,Y; char *Txt; short Len; };
  48. static struct CW_2 CW_s2[]={ 10,140,"EXIT",4,23,18,"R",1,73,18,"G",1,
  49.               123,18,"B",1,2,59,"<",1,140,59,">",1,40,80,"WaveForms",9,
  50.               105,115,"NEXT",4
  51.                };
  52.  
  53. void ColorWindow(scr)
  54. struct Screen *scr;
  55. {
  56. struct IntuiMessage *message;
  57. long choice,xcrd,ycrd;
  58. USHORT code;
  59.  
  60. CW_nwdw.Screen=scr;CW_cwdw=OpenWindow(&CW_nwdw);
  61.  
  62. CW_RGBflag=RED;CW_WaveFlag=1;
  63. _CWDrawWindow();
  64.  
  65. choice=NOTHING;
  66. while(choice!=EXIT)
  67. {
  68.  code=SELECTUP;
  69.  Wait( 1L << CW_cwdw->UserPort->mp_SigBit );
  70.  while(message=(struct IntuiMessage *)GetMsg(CW_cwdw->UserPort))
  71.   {
  72.    if(message!=0L)
  73.     {
  74.      code=message->Code;xcrd=message->MouseX;ycrd=message->MouseY;
  75.      ReplyMsg((struct Message *)message);
  76.      if(code==SELECTDOWN)
  77.       {
  78.        switch(choice=_CWGetChoice(xcrd,ycrd))
  79.         {
  80.          case EXIT: break;
  81.          case RED: { CW_RGBflag=RED;_CWDRGB();break;};
  82.          case GREEN: { CW_RGBflag=GREEN;_CWDRGB();break;};
  83.          case BLUE: { CW_RGBflag=BLUE;_CWDRGB();break;};
  84.          case COLLEFT:
  85.          case REDLEFT:
  86.          case GRELEFT:
  87.          case BLULEFT: { _CWLeft(choice);break;};
  88.          case COLRIGHT:
  89.          case REDRIGHT:
  90.          case GRERIGHT:
  91.          case BLURIGHT: { _CWRight(choice);break;};
  92.          case REDUP:
  93.          case GREENUP:
  94.          case BLUEUP: { _CWUp(choice);break;};
  95.          case REDDOWN:
  96.          case GREENDOWN:
  97.          case BLUEDOWN: { _CWDown(choice);break;};
  98.          case WAVE1:
  99.          case WAVE2:
  100.          case WAVE3:
  101.          case WAVE4:
  102.          case WAVE5: { _CWWave(choice);break;};
  103.          case WAVE6: { CW_WaveFlag=((CW_WaveFlag+1)>MAXWAVES)?1:CW_WaveFlag+1;
  104.                        _CWDrawWindow();break;};
  105.         };
  106.       };
  107.     };
  108.   };
  109. };
  110. CloseWindow(CW_cwdw);
  111. }
  112.  
  113. long _CWGetChoice(xcrd,ycrd)
  114. long xcrd,ycrd;
  115. {
  116. long flag;
  117. flag=NOTHING;
  118. if(ycrd<20)
  119.  {
  120.   if((xcrd>5)&&(xcrd<12))flag=REDUP;
  121.   if((xcrd>55)&&(xcrd<62))flag=GREENUP;
  122.   if((xcrd>105)&&(xcrd<112))flag=BLUEUP;
  123.  }
  124. else
  125. if(ycrd<40)
  126.  {
  127.   flag=BLURIGHT;
  128.   if(xcrd<140)flag=BLUE;
  129.   if(xcrd<110)flag=BLULEFT;
  130.   if(xcrd<100)flag=GRERIGHT;
  131.   if(xcrd<90)flag=GREEN;
  132.   if(xcrd<60)flag=GRELEFT;
  133.   if(xcrd<50)flag=REDRIGHT;
  134.   if(xcrd<40)flag=RED;
  135.   if(xcrd<10)flag=REDLEFT;
  136.  }
  137. else
  138. if(ycrd<50)
  139.  {
  140.   if((xcrd>5)&&(xcrd<12))flag=REDDOWN;
  141.   if((xcrd>55)&&(xcrd<62))flag=GREENDOWN;
  142.   if((xcrd>105)&&(xcrd<112))flag=BLUEDOWN;
  143.  }
  144. else
  145. if(ycrd<60)
  146.  {
  147.   if(xcrd<10)flag=COLLEFT;
  148.   if(xcrd>140)flag=COLRIGHT;
  149.  }
  150. else
  151. if(ycrd<85){ flag=NOTHING; } /* dummy */
  152. else
  153. if(ycrd<95)
  154.  {
  155.   if((xcrd>15)&&(xcrd<45))flag=WAVE1;
  156.   if((xcrd>60)&&(xcrd<90))flag=WAVE2;
  157.   if((xcrd>105)&&(xcrd<135))flag=WAVE3;
  158.  }
  159. else
  160. if(ycrd<105){ flag=NOTHING; } /* dummy */
  161. else
  162. if(ycrd<115)
  163.  {
  164.   if((xcrd>15)&&(xcrd<45))flag=WAVE4;
  165.   if((xcrd>60)&&(xcrd<90))flag=WAVE5;
  166.   if((xcrd>105)&&(xcrd<135))flag=WAVE6;
  167.  };
  168.  
  169. if((ycrd>132)&&(ycrd<142))
  170.  {
  171.   if((xcrd>9)&&(xcrd<48))flag=EXIT;
  172.  };
  173. return(flag);
  174. }
  175.  
  176. void _CWDrawWindow()
  177. {
  178. long col,index;
  179. SetDrMd(Rp,JAM1);
  180. SetAPen(Rp,1L);
  181. RectFill(Rp,1L,10L,149L,149L);
  182. SetAPen(Rp,0L);
  183.  
  184. /* Draw Boxes */
  185. for(index=0;index<9;index++)
  186. _CWBox((long)(CW_s1[index].Xmin),(long)(CW_s1[index].Ymin),(long)(CW_s1[index].Xmax),(long)(CW_s1[index].Ymax));
  187.  
  188. /* Draw TEXT */
  189. for(index=0;index<8;index++)
  190. { Move(Rp,(long)(CW_s2[index].X),(long)(CW_s2[index].Y));
  191.   Text(Rp,(UBYTE *)(CW_s2[index].Txt),(long)(CW_s2[index].Len));    };
  192. for(index=0;index<3;index++)
  193.  {
  194.    Move(Rp,index*50+2,33L);Text(Rp,"<",1L);
  195.    Move(Rp,index*50+5,18L);Text(Rp,"+",1L);
  196.    Move(Rp,index*50+5,47L);Text(Rp,"-",1L);
  197.    Move(Rp,index*50+42,33L);Text(Rp,">",1L);
  198.  };
  199. /* Draw TEXT END */
  200.  
  201. /* Draw color 2 - 32 */
  202. for(index=2;index<32;index++)
  203.  {
  204.    SetAPen(Rp,index);
  205.    RectFill(Rp,(long)(7+index*4),52L,(long)(10+index*4),60L);
  206.  };
  207.  
  208. /* Get RGB values for colors */
  209. CW_WVP=(struct ViewPort *)ViewPortAddress(CW_cwdw);
  210. for(index=0;index<32;index++)
  211.  {
  212.    col=GetRGB4(CW_WVP->ColorMap,index);
  213.    CW_red[index]=(col & 0x0f00)>>8;
  214.    CW_green[index]=(col & 0x00f0)>>4;
  215.    CW_blue[index]=(col & 0x000f);
  216.  };
  217. _CWDRGB();
  218.  
  219. /* Draw Waves */
  220. SetAPen(Rp,0L);
  221. if(CW_WaveFlag==1)
  222. {
  223. Move(Rp,15L,94L);Draw(Rp,45L,84L);
  224. Move(Rp,60L,94L);Draw(Rp,75L,84L);Draw(Rp,90L,94L);
  225. Move(Rp,105L,84L);Draw(Rp,135L,94L);
  226. /* WAVE 4 */
  227. Move(Rp,15L,114L);Draw(Rp,25L,104L);Draw(Rp,25L,114L);Draw(Rp,35L,104L);
  228. Draw(Rp,35L,114L);Draw(Rp,45L,104L);
  229. Move(Rp,60L,114L);Draw(Rp,90L,114L);
  230. };
  231. if(CW_WaveFlag==2)
  232. {
  233. Move(Rp,15L,94L);Draw(Rp,30L,84L);Draw(Rp,45L,84L);
  234. Move(Rp,60L,94L);Draw(Rp,70L,89L);Draw(Rp,80L,89L);Draw(Rp,90L,94L);
  235. Move(Rp,105L,84L);Draw(Rp,120L,84L);Draw(Rp,135L,94L);
  236. /* WAVE 4 */
  237. Move(Rp,15L,114L);Draw(Rp,30L,104L);Draw(Rp,30L,114L);Draw(Rp,45L,104L);
  238. Move(Rp,60L,104L);Draw(Rp,75L,114L);Draw(Rp,75L,104L);Draw(Rp,90L,114L);
  239. };
  240. }
  241.  
  242. void _CWBox(xmin,ymin,xmax,ymax)
  243. long xmin,ymin,xmax,ymax;
  244. {
  245.   SetAPen(Rp,0L);
  246.   RectFill(Rp,(long)(xmin-3),(long)(ymin-3),(long)(xmax+3),(long)(ymax+3));
  247.   SetAPen(Rp,1L);
  248.   RectFill(Rp,(long)(xmin-2),(long)(ymin-2),(long)(xmax+1),(long)(ymax+1));
  249.   SetAPen(Rp,0L);
  250. }
  251.  
  252. void _CWDRGB()
  253. {
  254. long index1,index2,tmp;
  255. for(index1=0;index1<3;index1++)
  256.  {
  257.   SetAPen(Rp,1L);
  258.   if((CW_RGBflag==RED)&&(index1==0))SetAPen(Rp,0L);
  259.   if((CW_RGBflag==GREEN)&&(index1==1))SetAPen(Rp,0L);
  260.   if((CW_RGBflag==BLUE)&&(index1==2))SetAPen(Rp,0L);
  261.   Move(Rp,(long)(index1*50+12),18L);
  262.   Text(Rp,"*  *",4L);
  263.  
  264.   SetAPen(Rp,0L);
  265.   RectFill(Rp,(long)(index1*50+9),20L,(long)(index1*50+41),40L);
  266.  
  267.   SetAPen(Rp,1L);
  268.   for(index2=2;index2<32;index2++)
  269.    {
  270.     switch(index1)
  271.      {
  272.       case 0: { tmp=CW_red[index2];break;};
  273.       case 1: { tmp=CW_green[index2];break;};
  274.       case 2: { tmp=CW_blue[index2];break;};
  275.      };
  276.     WritePixel(Rp,(long)(index1*50+8+index2),(long)(39-tmp));
  277.    };
  278.  };
  279. }
  280.  
  281. void _CWLeft(mask)
  282. long mask;
  283. {
  284. long index,tmpr,tmpg,tmpb;
  285. tmpr=CW_red[2];tmpg=CW_green[2];tmpb=CW_blue[2];
  286. for(index=2;index<31;index++)
  287.  {
  288.   if(mask&REDLEFT)CW_red[index]=CW_red[index+1];
  289.   if(mask&GRELEFT)CW_green[index]=CW_green[index+1];
  290.   if(mask&BLULEFT)CW_blue[index]=CW_blue[index+1];
  291.  };
  292. if(mask&REDLEFT)CW_red[31]=tmpr;
  293. if(mask&GRELEFT)CW_green[31]=tmpg;
  294. if(mask&BLULEFT)CW_blue[31]=tmpb;
  295. _CWSetColMap();
  296. _CWDRGB();
  297. }
  298.  
  299. void _CWRight(mask)
  300. long mask;
  301. {
  302. long index,tmpr,tmpg,tmpb;
  303. tmpr=CW_red[31];tmpg=CW_green[31];tmpb=CW_blue[31];
  304. for(index=31;index>2;index--)
  305.  {
  306.   if(mask&REDRIGHT)CW_red[index]=CW_red[index-1];
  307.   if(mask&GRERIGHT)CW_green[index]=CW_green[index-1];
  308.   if(mask&BLURIGHT)CW_blue[index]=CW_blue[index-1];
  309.  };
  310. if(mask&REDRIGHT)CW_red[2]=tmpr;
  311. if(mask&GRERIGHT)CW_green[2]=tmpg;
  312. if(mask&BLURIGHT)CW_blue[2]=tmpb;
  313. _CWSetColMap();
  314. _CWDRGB();
  315. }
  316.  
  317. void _CWSetColMap()
  318. {
  319. long index;
  320. for(index=2L;index<32L;index++)
  321.  {
  322.    SetRGB4(CW_WVP,index,(long)CW_red[index],(long)CW_green[index],(long)CW_blue[index]);
  323.  };
  324. }
  325.  
  326. void _CWUp(choice)
  327. long choice;
  328. {
  329. long index;
  330. for(index=2;index<32;index++)
  331.  {
  332.   if(choice==REDUP)CW_red[index]=((CW_red[index]+1)>15)?0:CW_red[index]+1;
  333.   if(choice==GREENUP)CW_green[index]=((CW_green[index]+1)>15)?0:CW_green[index]+1;
  334.   if(choice==BLUEUP)CW_blue[index]=((CW_blue[index]+1)>15)?0:CW_blue[index]+1;
  335.   SetRGB4(CW_WVP,(long)index,(long)CW_red[index],(long)CW_green[index],
  336.           (long)CW_blue[index]);
  337.  };
  338. _CWDRGB();
  339. }
  340.  
  341. void _CWDown(choice)
  342. long choice;
  343. {
  344. long index;
  345. for(index=2;index<32;index++)
  346.  {
  347.   if(choice==REDDOWN)CW_red[index]=((CW_red[index]-1)<0)?15:CW_red[index]-1;
  348.   if(choice==GREENDOWN)CW_green[index]=((CW_green[index]-1)<0)?15:CW_green[index]-1;
  349.   if(choice==BLUEDOWN)CW_blue[index]=((CW_blue[index]-1)<0)?15:CW_blue[index]-1;
  350.   SetRGB4(CW_WVP,(long)index,(long)CW_red[index],(long)CW_green[index],
  351.           (long)CW_blue[index]);
  352.  };
  353. _CWDRGB();
  354. }
  355.  
  356. void _CWWave(choice)
  357. long choice;
  358. {
  359. long index,tmp;
  360. for(index=0;index<30;index++)
  361.  {
  362.   tmp=0;
  363.   switch(CW_WaveFlag)
  364.      {
  365.      case 1:
  366.         {
  367.         switch(choice)
  368.            {  case WAVE1: { tmp=index / 2;break;};
  369.               case WAVE2: { tmp=(index<15)?index:(30-index);break;};
  370.               case WAVE3: { tmp=15-index/2;break;};
  371.               case WAVE4: { tmp=index % 10;break;};
  372.               case WAVE5: { tmp=0;break;};
  373.            };
  374.         break;};
  375.      case 2:
  376.         {
  377.         switch(choice)
  378.            {  case WAVE1: { tmp=(index>15)?15:index;break;};
  379.               case WAVE2: { tmp=(index<15)?index:(30-index);
  380.                             tmp=(tmp>10)?10:tmp;break;};
  381.               case WAVE3: { tmp=((30-index)>15)?15:(30-index);break;};
  382.               case WAVE4: { tmp=index % 15;break;};
  383.               case WAVE5: { tmp=15-index % 15;break;};
  384.            };
  385.         break;};
  386.      };
  387.    switch(CW_RGBflag)
  388.     { case RED: { CW_red[index+2]=tmp;break;};
  389.       case GREEN: { CW_green[index+2]=tmp;break;};
  390.       case BLUE: { CW_blue[index+2]=tmp;break;};
  391.     };
  392.  
  393.  };
  394. _CWSetColMap();_CWDRGB();
  395. }
  396.  
  397.  
  398.  
  399.  
  400.